package cn.edu360.streaming.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * 字符串工具类
 * wzxjava@126.com
 * Created by wangzhixuan on 2017/05/18 20:12
 */
public class StrUtil {
    /**
     * 字符串为 null 或者为  "" 时返回 true
     */
    public static boolean isBlank(String str) {
        return str == null || "".equals(str.trim());
    }

    /**
     * 字符串不为 null 而且不为  "" 时返回 true
     */
    public static boolean notBlank(String str) {
        return str != null && !"".equals(str.trim());
    }

    public static String[] split(String str, char delimiter) {
        List<String> results = new ArrayList<>();

        int ipos, lastpos = 0;
        while ((ipos = str.indexOf(delimiter, lastpos)) != -1) {
            results.add(str.substring(lastpos, ipos));
            lastpos = ipos + 1;
        }
        if (lastpos < str.length()) {
            results.add(str.substring(lastpos));
        }
        return results.toArray(new String[results.size()]);
    }

}
